//
// Created by liangwenhao on 2024/4/4.
//

#ifndef _MOTOR_DRIVER_H
#define _MOTOR_DRIVER_H
#include "stdio.h"
#include "pid_calculation.h"
#include "rc_driver.h"
#include "bsp_can.h"
#include "can_send_task.h"
#include "yaw_control.h"
#define MOTOR3508_SPEED_MAX 9600.f
#define MOTOR3508_ANGLE_MAX 8191.f
#define MOTOR3508_CURRENT_MAX 16384.f

#define MOTOR2006_SPEED_MAX 21000.f
#define MOTOR2006_ANGLE_MAX 8191.f
#define MOTOR2006_CURRENT_MAX 10000.f

#define MOTOR6020_SPEED_MAX 320.f
#define MOTOR6020_ANGLE_MAX 8191.f
#define MOTOR6020_VOLTAGE_MAX 30000.f

#define PitchMotorForm 1
#define YawMotorForm 2
#define LoadMotorForm 3
#define LocateMotorForm 4
enum DJI_MOTOR_TYPE {
    DJI_M3508 = 0,
    DJI_M2006 = 1,
    DJI_GM6020 = 2,
};
void Motor_canTx_calculation(Motor * motor,CAN_Send * canTx);
void Motor_canRx_calculation(Motor * motor,const uint8_t * canRx);

void Motor_Init(Motor * motor,uint8_t num,uint8_t motor_form,uint8_t formID);

void Motor_real_speed_set(Motor * motor,float real_speed,CAN_Send * can_send);
void Motor_real_angle_set(Motor * motor,float real_angle,CAN_Send * can_send);
void YawMotor_angle_set(float TargetAngle);
void Motor_Flag_change(Motor * motor);
void LoadMotor_real_angle_set(float angle_cross);
/* 滤波系数设置为1的时候即关闭滤波 */
#define SPEED_SMOOTH_COEF 0.85f      // 最好大于0.85
#define CURRENT_SMOOTH_COEF 0.9f     // 必须大于0.9
#define ECD_ANGLE_COEF_DJI 0.043945f // (360/8192),将编码器值转化为角度制




#endif //_MOTOR_DRIVER_H